from jili.core import keyword
from jili.trade.constants import subjects
"""as 
from jili.core.printlog import print,config
config("/root/logs/mohe/trade_adapter_ctp","file","m")
gpath="_tmp_trade_"
istest=True
gpath="//temp//ctptrader//"
onadatersubject="adater_onctp"
"""

import threading
import PyCTP
from jili.core import moheengine as mh
mh.setmax_workers(3)
from jili.tool.state import ismongo,isredis
import redis
import pickle
pool = redis.ConnectionPool(host='127.0.0.1')
r = redis.Redis(connection_pool=pool)
def setredis(key,value):
    if isredis:
        r.set(key, pickle.dumps(value))
def setredis_map(name,key,data):
    if isredis:
        r.hset(name, key, pickle.dumps(data))
__adatersubject="adater_ctp"
def bytes2str(d):
    if isinstance(d,dict):
        for k,v in d.items():
            if isinstance(v,bytes):
                d[k]=str(v, encoding = "gbk")
    elif isinstance(d,str):
        d=str(d, encoding = "gbk")
    return d
def str2bytes(s):
    if isinstance(s,str):
        s=bytes(s,encoding = "gbk")
    elif isinstance(s,dict):
        for k,v in s.items():
            if isinstance(v,str):
                s[k]=bytes(v, encoding = "gbk")
    return s

class PyCTP_Trader(PyCTP.CThostFtdcTraderApi):

    TIMEOUT = 30
    version="CTP Adapter 1.0.1"
    __subject_up=subjects["ctp"]["up"]
    __subject_down=subjects["ctp"]["dwon"]
    __RequestID = 0
    __OrderRef = 0
    isLogined = False
    isauth=False
    __idmap={}
    __orderidmap={}
    __HedgeFlag=b"1"# touji
    __OrderPriceType=b"2"
    __VolumeCondition=b"1"
    __TimeCondition=b"3"
    __IPAddress=b""
    __MacAddress=b""
    __CurrencyID=b'CNY'
    __BizType=b'1'

    @staticmethod
    def create(investorid,config):
        gpath=config["tmppath"]
        path = gpath + investorid
        path = str2bytes(path)
        print(investorid,"path:", path)
        return PyCTP_Trader.CreateFtdcTraderApi(path)
    @staticmethod
    def getversion():
        version = str(PyCTP.CThostFtdcTraderApi.GetApiVersion(), encoding="gbk")
        return "pyctp CTP trader API version: " + version
    def __IncRequestID(self):
        """ 自增并返回请求ID """
        self.__RequestID += 1
        return self.__RequestID
    def __IncOrderRef(self):
        """ 自增并返回请求ID """
        self.__OrderRef += 1
        return self.__OrderRef
    def setInvestorID(self, InvestorID):
        self.__InvestorID = str2bytes(InvestorID)
        self.__InvestorIDstr = InvestorID
        return self.__InvestorID

    def init(self,config):
        self.config=config
        self.RegisterSpi(self)
        if "private" in self.config["login_data"].keys():
            private=int(self.config["login_data"]["private"])
        else:
            private = PyCTP.THOST_TERT_QUICK
        public = PyCTP.THOST_TERT_RESUME
        self.SubscribePrivateTopic(private)
        self.SubscribePublicTopic(public)
        self.settleinfo=""
        self.__onlinenum=0
        self.onlinepid=[]
        self.BrokerID=self.config["BrokerID"]
        for ip in self.config["RegisterFront_trade"][self.BrokerID]:
            self.RegisterFront(str2bytes(ip))
    def Connect(self):
        """ 连接前置服务器 """
        #self.RegisterSpi(self)
        #self.SubscribePrivateTopic(PyCTP.THOST_TERT_RESUME)
        #self.SubscribePublicTopic(PyCTP.THOST_TERT_RESUME)
        #self.RegisterFront(frontAddr)
        self.Init()
        self.__rsp_Connect = dict(event=threading.Event())
        self.__rsp_Connect['event'].clear()
        return 0 if self.__rsp_Connect['event'].wait(self.TIMEOUT) else -4

    def Login(self, rsq):
        """ 用户登录请求 """
        pid=rsq["PID"]
        if  self.isauth:
            if not self.isLogined:
                autoid=self.__IncRequestID()
                self.__idmap[autoid]=rsq["RequestID"]
                rsq=str2bytes(rsq)
                reqUserLogin = dict(BrokerID    = rsq["BrokerID"]
                                    , UserID    = rsq["UserID"]
                                    , Password  = rsq["Password"])
                self.__rsp_Login = dict(event       = threading.Event()
                                        , RequestID = autoid)
                ret = self.ReqUserLogin(reqUserLogin, autoid)
                if ret == 0:
                    self.__rsp_Login['event'].clear()
                    if self.__rsp_Login['event'].wait(self.TIMEOUT):
                        if self.__rsp_Login["RspInfo"]['ErrorID'] == 0:
                            self.isLogined = True
                            if pid not in self.onlinepid:
                                self.__onlinenum=self.__onlinenum+1
                                self.onlinepid.append(pid)
                            self.__Password = str2bytes(rsq["Password"])
                            del self.__rsp_Login['event']
                        else:
                            print(self.__rsp_Login["RspInfo"]['ErrorMsg'])
                        return self.__rsp_Login["RspInfo"]['ErrorID']
                    else:
                        return -4
            else:
                #print(self.__rsp_Login)
                self.__rsp_Login["RequestID"]=rsq["RequestID"]
                if pid not in self.onlinepid:
                    self.__onlinenum=self.__onlinenum+1
                    self.onlinepid.append(pid)
                mh.safesend(self.__subject_down,self.__InvestorIDstr,self.__rsp_Login)
                return 0
        else:
            return -4
    def Logout(self,rsq):
        """ 登出请求 """
        pid=rsq["PID"]
        if  self.isLogined:
            if pid in self.onlinepid:
                self.__onlinenum=self.__onlinenum-1
                self.onlinepid.remove(pid)
                if self.__onlinenum==0:
                    autoid=self.__IncRequestID()
                    self.__idmap[autoid]=rsq["RequestID"]
                    reqUserLogout = dict(BrokerID = self.__BrokerID,UserID = self.__UserID)
                    self.__rsp_Logout = dict(event      = threading.Event()
                                            , RequestID = self.__IncRequestID())
                    ret = self.ReqUserLogout(reqUserLogout, self.__rsp_Logout['RequestID'])
                    msg={}
                    msg["cmd"]="OnRspUserLogout"
                    msg["data"]=""
                    msg["RspInfo"]=dict(ErrorID=ret,ErrorMsg="logout success")
                    msg["RequestID"]=rsq["RequestID"]
                    msg["IsLast"]=True
                    mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
                    return ret
                else:
                    msg={}
                    msg["cmd"]="OnRspUserLogout"
                    msg["data"]=""
                    msg["RspInfo"]=dict(ErrorID=0,ErrorMsg="logout success")
                    msg["RequestID"]=rsq["RequestID"]
                    msg["IsLast"]=True
                    mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
                    return 0
            else:
                msg={}
                msg["cmd"]="OnRspUserLogout"
                msg["data"]=""
                msg["RspInfo"]=dict(ErrorID=0,ErrorMsg="logout success")
                msg["RequestID"]=rsq["RequestID"]
                msg["IsLast"]=True
                mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
                return 0
        else:
            msg={}
            msg["cmd"]="OnRspUserLogout"
            msg["data"]=""
            msg["RspInfo"]=dict(ErrorID=0,ErrorMsg="no login")
            msg["RequestID"]=rsq["RequestID"]
            msg["IsLast"]=True
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
            return 0
    def OnFrontConnected(self):
        """ 当客户端与交易后台建立起通信连接时（还未登录前），该方法被调用。 """
        self.__rsp_Connect['event'].set()

    def OnFrontDisconnected(self, nReason):
        """ 当客户端与交易后台通信连接断开时，该方法被调用。当发生这个情况后，API会自动重新连接，客户端可不做处理。
        nReason 错误原因
        0x1001 网络读失败
        0x1002 网络写失败
        0x2001 接收心跳超时
        0x2002 发送心跳失败
        0x2003 收到错误报文        
        """
        pass
        # 登陆状态时掉线, 自动重登陆
        #if self.__isLogined:
        #    self.__Inst_Interval()
        #    sys.stderr.write('自动登陆: %d' % self.Login(self.__BrokerID, self.__UserID, self.__Password))
    def reqAuthenticate(self,brokerID,userID): 
        RequestID=self.__IncRequestID()
        self.__auth = dict(event= threading.Event()
                                    , RequestID = RequestID)
        CThostFtdcReqAuthenticateField=dict( 
            BrokerID=str2bytes(brokerID)
            ,UserID=str2bytes(userID)
            ,UserProductInfo=b''
            ,AuthCode=b'R20HA8U4K64TFZBR'
            ,AppID=b'client_byats_2.1.0'
        ) 
        ret = self.ReqAuthenticate(CThostFtdcReqAuthenticateField,RequestID)
        if ret==0:
            self.__auth['event'].clear()
            if self.__auth['event'].wait(self.TIMEOUT):
                if self.__auth["RspInfo"]['ErrorID'] == 0:
                    self.isauth = True
                    del self.__auth['event']
                else:
                    print(self.__auth["RspInfo"]['ErrorMsg'])
                return self.__auth["RspInfo"]['ErrorID']
            else:
                return -4
    def OnRspAuthenticate(self,RspAuthenticateField,RspInfo, RequestID, IsLast):
        if RequestID == self.__auth['RequestID'] and IsLast:
            msg={}
            msg["cmd"]="OnRspAuthenticate"
            msg["data"]=bytes2str(RspAuthenticateField)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=RequestID
            msg["IsLast"]=IsLast
            self.__auth.update(msg)
            print("OnRspAuthenticate ",msg)
            self.__auth['event'].set()
            #mh.safesend(self.__qrysubject,self.__InvestorIDstr,msg)
    def OnRspUserLogin(self, RspUserLogin, RspInfo, RequestID, IsLast):
        """ 登录请求响应 """
        if RequestID == self.__rsp_Login['RequestID'] and IsLast:
            self.__BrokerID = RspUserLogin['BrokerID']
            self.__UserID = RspUserLogin['UserID']
            self.__SystemName = RspUserLogin['SystemName']
            self.__TradingDay = RspUserLogin['TradingDay']
            self.__DCETime = RspUserLogin['DCETime']
            self.__SessionID = RspUserLogin['SessionID'] 
            self.__MaxOrderRef = RspUserLogin['MaxOrderRef']
            if self.__MaxOrderRef!=b'':
                self.__OrderRef = int(self.__MaxOrderRef) # 初始化报单引用
            else:
                self.__OrderRef =0
            self.__INETime = RspUserLogin['INETime']
            self.__LoginTime = RspUserLogin['LoginTime']
            self.__FrontID = RspUserLogin['FrontID']
            self.__FFEXTime = RspUserLogin['FFEXTime']
            self.__CZCETime = RspUserLogin['CZCETime']
            self.__SHFETime = RspUserLogin['SHFETime']
            if RequestID in self.__idmap.keys():
                msg={}
                msg["cmd"]="OnRspUserLogin"
                msg["data"]=bytes2str(RspUserLogin)
                msg["RspInfo"]=bytes2str(RspInfo)
                msg["RequestID"]=self.__idmap[RequestID]
                msg["IsLast"]=IsLast
                self.__rsp_Login.update(msg)
                print("on login ",msg)
                mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
            self.__rsp_Login['event'].set()
        
        
    def OnRspUserLogout(self, RspUserLogout, RspInfo, RequestID, IsLast):
        """ 登出请求响应 """
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspUserLogout"
            msg["data"]=bytes2str(RspUserLogout)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            self.__rsp_Logout.update(msg)
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
        if RequestID == self.__rsp_Logout['RequestID'] and IsLast:
            self.__rsp_Logout['event'].set()
    def OnRspSettlementInfoConfirm(self,SettlementInfoConfirm,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspSettlementInfoConfirm"
            msg["data"]=bytes2str(SettlementInfoConfirm)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
            key=keyword.ctp_settlement+self.__InvestorIDstr
            setredis(key,msg)
    def OnRspQryOrder(self,Order,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys() :
            if Order   is not None:
                msg={}
                msg["cmd"]="OnRspQryOrder"
                msg["data"]=bytes2str(Order)
                msg["RspInfo"]=bytes2str(RspInfo)
                msg["RequestID"]=self.__idmap[RequestID]
                msg["IsLast"]=IsLast
                oid=msg["data"]["OrderRef"]
                if oid in  self.__orderidmap.keys():
                    msg["data"]["orderid"]=self.__orderidmap[oid]
                else:
                    msg["data"]["orderid"]=str(Order["OrderRef"])+"."+str(Order["FrontID"])+"."+str(Order["SessionID"])
                mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
                name=keyword.ctp_order+self.__InvestorIDstr
                key=msg["data"]["orderid"]
                setredis_map(name,key,msg)
            else:
                print("ONOrder:",Order,RspInfo, RequestID, IsLast)
    def OnRspQryTrade(self,Trade,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            if Trade is not None:
                msg={}
                msg["cmd"]="OnRspQryTrade"
                msg["data"]=bytes2str(Trade)
                msg["RspInfo"]=bytes2str(RspInfo)
                msg["RequestID"]=self.__idmap[RequestID]
                msg["IsLast"]=IsLast
                oid=msg["data"]["OrderRef"]
                if oid in  self.__orderidmap.keys():
                    msg["data"]["orderid"]=self.__orderidmap[oid]
                else:
                    msg["data"]["orderid"]=str(Trade["OrderRef"])+"."+str(Trade["TraderID"])
                mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
            else:
                print("ONTrade:",Trade,RspInfo, RequestID, IsLast)
    def OnRspQryInvestorPosition(self,InvestorPosition,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryInvestorPosition"
            msg["data"]=bytes2str(InvestorPosition)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            pos=msg["data"]
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
                #if pos["Position"]!=0:
            if pos:
                name=keyword.ctp_pos+self.__InvestorIDstr
                key=pos["InstrumentID"]+"."+pos["PosiDirection"]
                setredis_map(name,key,msg)
    def OnRspQryTradingAccount(self,TradingAccount,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryTradingAccount"
            msg["data"]=bytes2str(TradingAccount)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
            key=keyword.ctp_fund+self.__InvestorIDstr
            setredis(key,msg)
    def OnRspQrySettlementInfo(self,SettlementInfo,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQrySettlementInfo"
            msg["data"]=bytes2str(SettlementInfo)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            self.settleinfo=self.settleinfo+msg["data"]["Content"]
            if IsLast:
                key=keyword.ctp_settlinfo+self.__InvestorIDstr
                self.settleinfo=self.settleinfo+msg["data"]["Content"]
                setredis(key,self.settleinfo)
                self.settleinfo=""
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnOrder(self,Order):
        if Order is not None:
            msg={}
            msg["cmd"]="OnRtnOrder"
            msg["data"]=bytes2str(Order)
            oid=msg["data"]["OrderRef"]
            if oid in  self.__orderidmap.keys():
                msg["data"]["orderid"]=self.__orderidmap[oid]
            else:
                msg["data"]["orderid"]=str(Order["OrderRef"])+"."+str(Order["FrontID"])+"."+str(Order["SessionID"])
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
            if Order:
                name="ctp_order_"+self.__InvestorIDstr
                key=msg["data"]["orderid"]
                setredis_map(name,key,msg)
    def OnRtnTrade(self,Trade):
        if Trade is not None:
            msg={}
            msg["cmd"]="OnRtnTrade"
            msg["data"]=bytes2str(Trade)
            oid=msg["data"]["OrderRef"]
            if oid in  self.__orderidmap.keys():
                msg["data"]["orderid"]=self.__orderidmap[oid]
            else:
                msg["data"]["orderid"]=str(Trade["OrderRef"])+"."+str(Trade["TraderID"])
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnOrderInsert(self,InputOrder, RspInfo):
        if InputOrder is not None:
            msg={}
            msg["cmd"]="OnErrRtnOrderInsert"
            msg["data"]=bytes2str(InputOrder)
            msg["RspInfo"]=bytes2str(RspInfo)
            oid=msg["data"]["OrderRef"]
            if oid in  self.__orderidmap.keys():
                msg["data"]["orderid"]=self.__orderidmap[oid]
            else:
                msg["data"]["orderid"]=oid
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnOrderAction(self,OrderAction, RspInfo):
        if OrderAction is not None:
            msg={}
            msg["cmd"]="OnErrRtnOrderAction"
            msg["data"]=bytes2str(OrderAction)
            msg["RspInfo"]=bytes2str(RspInfo)
            oid=msg["data"]["OrderRef"]
            if oid in  self.__orderidmap.keys():
                msg["data"]["orderid"]=self.__orderidmap[oid]
            else:
                msg["data"]["orderid"]=oid
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspOrderInsert(self,InputOrder,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspOrderInsert"
            msg["data"]=bytes2str(InputOrder)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            oid=msg["data"]["OrderRef"]
            if oid in  self.__orderidmap.keys():
                msg["data"]["orderid"]=self.__orderidmap[oid]
            else:
                msg["data"]["orderid"]=oid
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspParkedOrderInsert(self,ParkedOrder,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspParkedOrderInsert"
            msg["data"]=bytes2str(ParkedOrder)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            oid=msg["data"]["OrderRef"]
            if oid in  self.__orderidmap.keys():
                msg["data"]["orderid"]=self.__orderidmap[oid]
            else:
                msg["data"]["orderid"]=oid
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspParkedOrderAction(self,ParkedOrderAction,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspParkedOrderAction"
            msg["data"]=bytes2str(ParkedOrderAction)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            oid=msg["data"]["OrderRef"]
            if oid in  self.__orderidmap.keys():
                msg["data"]["orderid"]=self.__orderidmap[oid]
            else:
                msg["data"]["orderid"]=oid
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspOrderAction(self,InputOrderAction,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspOrderAction"
            msg["data"]=bytes2str(InputOrderAction)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            oid=msg["data"]["OrderRef"]
            if oid in  self.__orderidmap.keys():
                msg["data"]["orderid"]=self.__orderidmap[oid]
            else:
                msg["data"]["orderid"]=oid
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def reqOrderInsert(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        orderref=str(self.__IncOrderRef())
        if "orderid" in rsq.keys():
            oid=rsq["orderid"]
            self.__orderidmap[orderref]=oid
        rsq=str2bytes(rsq)
        CThostFtdcInputOrderField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,OrderRef=bytes(orderref,encoding="gbk")
            ,UserID=self.__UserID
            ,OrderPriceType=self.__OrderPriceType
            ,Direction=b''
            ,CombOffsetFlag=b''
            ,CombHedgeFlag=self.__HedgeFlag
            ,LimitPrice=0.0
            ,VolumeTotalOriginal=0
            ,TimeCondition=self.__TimeCondition
            ,GTDDate=b''
            ,VolumeCondition=self.__VolumeCondition
            ,MinVolume=1
            ,ContingentCondition=b'1'
            ,StopPrice=0.0
            ,ForceCloseReason=b'0'
            ,IsAutoSuspend=0
            ,BusinessUnit=b''
            ,RequestID=self.__RequestID
            ,UserForceClose=0
            ,IsSwapOrder=0
            ,ExchangeID=b''
            ,InvestUnitID=b''
            ,AccountID=b''
            ,CurrencyID=b''
            ,ClientID=b''
            ,IPAddress=self.__IPAddress
            ,MacAddress=self.__MacAddress
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcInputOrderField.keys():
                if k not in ["RequestID","OrderRef"]:
                    CThostFtdcInputOrderField[k]=v
        print(CThostFtdcInputOrderField)
        self.ReqOrderInsert(CThostFtdcInputOrderField,RequestID)
    def reqParkedOrderInsert(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        orderref=str(self.__IncOrderRef())
        if "orderid" in rsq.keys():
            oid=rsq["orderid"]
            self.__orderidmap[orderref]=oid
        rsq=str2bytes(rsq)
        CThostFtdcParkedOrderField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,OrderRef=bytes(orderref,encoding="gbk")
            ,UserID=self.__UserID
            ,OrderPriceType=self.__OrderPriceType
            ,Direction=b''
            ,CombOffsetFlag=b''
            ,CombHedgeFlag=self.__HedgeFlag
            ,LimitPrice=0.0
            ,VolumeTotalOriginal=0
            ,TimeCondition=self.__TimeCondition
            ,GTDDate=b''
            ,VolumeCondition=self.__VolumeCondition
            ,MinVolume=0
            ,ContingentCondition=b''
            ,StopPrice=0.0
            ,ForceCloseReason=b''
            ,IsAutoSuspend=0
            ,BusinessUnit=b''
            ,RequestID=self.__RequestID
            ,UserForceClose=0
            ,ExchangeID=b''
            ,ParkedOrderID=b''
            ,UserType=b''
            ,Status=b''
            ,ErrorID=0
            ,ErrorMsg=b''
            ,IsSwapOrder=0
            ,AccountID=b''
            ,CurrencyID=b''
            ,ClientID=b''
            ,InvestUnitID=b''
            ,IPAddress=self.__IPAddress
            ,MacAddress=self.__MacAddress
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcParkedOrderField.keys():
                if k not in ["RequestID","OrderRef"]:
                    CThostFtdcParkedOrderField[k]=v
        self.ReqParkedOrderInsert(CThostFtdcParkedOrderField,RequestID)
    def reqParkedOrderAction(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        orderref=self.__IncOrderRef()
        if "orderid" in rsq.keys():
            oid=rsq["orderid"]
            self.__orderidmap[orderref]=oid
        rsq=str2bytes(rsq)
        CThostFtdcParkedOrderActionField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,OrderActionRef=orderref
            ,OrderRef=b''
            ,RequestID=self.__RequestID
            ,FrontID=0
            ,SessionID=0
            ,ExchangeID=b''
            ,OrderSysID=b''
            ,ActionFlag=b''
            ,LimitPrice=0.0
            ,VolumeChange=0
            ,UserID=self.__UserID
            ,InstrumentID=b''
            ,ParkedOrderActionID=b''
            ,UserType=b''
            ,Status=b''
            ,ErrorID=0
            ,ErrorMsg=b''
            ,InvestUnitID=b''
            ,IPAddress=self.__IPAddress
            ,MacAddress=self.__MacAddress
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcParkedOrderActionField.keys():
                if k not in ["RequestID","OrderActionRef"]:
                    CThostFtdcParkedOrderActionField[k]=v
        self.ReqParkedOrderAction(CThostFtdcParkedOrderActionField,RequestID)
    def reqOrderAction(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        orderref=self.__IncOrderRef()
        if "orderid" in rsq.keys():
            oid=rsq["orderid"]
            self.__orderidmap[orderref]=oid
        rsq=str2bytes(rsq)
        CThostFtdcInputOrderActionField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,OrderActionRef=orderref
            ,OrderRef=b''
            ,RequestID=self.__RequestID
            ,FrontID=0
            ,SessionID=0
            ,ExchangeID=b''
            ,OrderSysID=b''
            ,ActionFlag=b''
            ,LimitPrice=0.0
            ,VolumeChange=0
            ,UserID=self.__UserID
            ,InstrumentID=b''
            ,InvestUnitID=b''
            ,IPAddress=self.__IPAddress
            ,MacAddress=self.__MacAddress
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcInputOrderActionField.keys():
                if k not in ["RequestID","OrderActionRef"]:
                    CThostFtdcInputOrderActionField[k]=v
        self.ReqOrderAction(CThostFtdcInputOrderActionField,RequestID)





























































##############--------------升级替换处-----------------------#################
    def OnRspUserPasswordUpdate(self,UserPasswordUpdate,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspUserPasswordUpdate"
            msg["data"]=bytes2str(UserPasswordUpdate)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspTradingAccountPasswordUpdate(self,TradingAccountPasswordUpdate,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspTradingAccountPasswordUpdate"
            msg["data"]=bytes2str(TradingAccountPasswordUpdate)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQueryMaxOrderVolume(self,QueryMaxOrderVolume,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQueryMaxOrderVolume"
            msg["data"]=bytes2str(QueryMaxOrderVolume)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspRemoveParkedOrder(self,RemoveParkedOrder,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspRemoveParkedOrder"
            msg["data"]=bytes2str(RemoveParkedOrder)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspRemoveParkedOrderAction(self,RemoveParkedOrderAction,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspRemoveParkedOrderAction"
            msg["data"]=bytes2str(RemoveParkedOrderAction)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspExecOrderInsert(self,InputExecOrder,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspExecOrderInsert"
            msg["data"]=bytes2str(InputExecOrder)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspExecOrderAction(self,InputExecOrderAction,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspExecOrderAction"
            msg["data"]=bytes2str(InputExecOrderAction)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspForQuoteInsert(self,InputForQuote,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspForQuoteInsert"
            msg["data"]=bytes2str(InputForQuote)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQuoteInsert(self,InputQuote,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQuoteInsert"
            msg["data"]=bytes2str(InputQuote)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQuoteAction(self,InputQuoteAction,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQuoteAction"
            msg["data"]=bytes2str(InputQuoteAction)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspBatchOrderAction(self,InputBatchOrderAction,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspBatchOrderAction"
            msg["data"]=bytes2str(InputBatchOrderAction)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspCombActionInsert(self,InputCombAction,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspCombActionInsert"
            msg["data"]=bytes2str(InputCombAction)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryInvestor(self,Investor,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryInvestor"
            msg["data"]=bytes2str(Investor)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryTradingCode(self,TradingCode,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryTradingCode"
            msg["data"]=bytes2str(TradingCode)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryInstrumentMarginRate(self,InstrumentMarginRate,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryInstrumentMarginRate"
            msg["data"]=bytes2str(InstrumentMarginRate)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryInstrumentCommissionRate(self,InstrumentCommissionRate,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryInstrumentCommissionRate"
            msg["data"]=bytes2str(InstrumentCommissionRate)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryExchange(self,Exchange,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryExchange"
            msg["data"]=bytes2str(Exchange)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryProduct(self,Product,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryProduct"
            msg["data"]=bytes2str(Product)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryInstrument(self,Instrument,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryInstrument"
            msg["data"]=bytes2str(Instrument)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryDepthMarketData(self,DepthMarketData,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryDepthMarketData"
            msg["data"]=bytes2str(DepthMarketData)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryTransferBank(self,TransferBank,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryTransferBank"
            msg["data"]=bytes2str(TransferBank)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryInvestorPositionDetail(self,InvestorPositionDetail,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryInvestorPositionDetail"
            msg["data"]=bytes2str(InvestorPositionDetail)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryNotice(self,Notice,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryNotice"
            msg["data"]=bytes2str(Notice)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQrySettlementInfoConfirm(self,SettlementInfoConfirm,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQrySettlementInfoConfirm"
            msg["data"]=bytes2str(SettlementInfoConfirm)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryInvestorPositionCombineDetail(self,InvestorPositionCombineDetail,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryInvestorPositionCombineDetail"
            msg["data"]=bytes2str(InvestorPositionCombineDetail)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryCFMMCTradingAccountKey(self,CFMMCTradingAccountKey,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryCFMMCTradingAccountKey"
            msg["data"]=bytes2str(CFMMCTradingAccountKey)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryEWarrantOffset(self,EWarrantOffset,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryEWarrantOffset"
            msg["data"]=bytes2str(EWarrantOffset)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryInvestorProductGroupMargin(self,InvestorProductGroupMargin,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryInvestorProductGroupMargin"
            msg["data"]=bytes2str(InvestorProductGroupMargin)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryExchangeMarginRate(self,ExchangeMarginRate,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryExchangeMarginRate"
            msg["data"]=bytes2str(ExchangeMarginRate)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryExchangeMarginRateAdjust(self,ExchangeMarginRateAdjust,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryExchangeMarginRateAdjust"
            msg["data"]=bytes2str(ExchangeMarginRateAdjust)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryExchangeRate(self,ExchangeRate,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryExchangeRate"
            msg["data"]=bytes2str(ExchangeRate)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQrySecAgentACIDMap(self,SecAgentACIDMap,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQrySecAgentACIDMap"
            msg["data"]=bytes2str(SecAgentACIDMap)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryProductExchRate(self,ProductExchRate,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryProductExchRate"
            msg["data"]=bytes2str(ProductExchRate)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryProductGroup(self,ProductGroup,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryProductGroup"
            msg["data"]=bytes2str(ProductGroup)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryMMInstrumentCommissionRate(self,MMInstrumentCommissionRate,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryMMInstrumentCommissionRate"
            msg["data"]=bytes2str(MMInstrumentCommissionRate)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryMMOptionInstrCommRate(self,MMOptionInstrCommRate,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryMMOptionInstrCommRate"
            msg["data"]=bytes2str(MMOptionInstrCommRate)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryInstrumentOrderCommRate(self,InstrumentOrderCommRate,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryInstrumentOrderCommRate"
            msg["data"]=bytes2str(InstrumentOrderCommRate)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryOptionInstrTradeCost(self,OptionInstrTradeCost,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryOptionInstrTradeCost"
            msg["data"]=bytes2str(OptionInstrTradeCost)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryOptionInstrCommRate(self,OptionInstrCommRate,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryOptionInstrCommRate"
            msg["data"]=bytes2str(OptionInstrCommRate)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryExecOrder(self,ExecOrder,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryExecOrder"
            msg["data"]=bytes2str(ExecOrder)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryForQuote(self,ForQuote,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryForQuote"
            msg["data"]=bytes2str(ForQuote)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryQuote(self,Quote,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryQuote"
            msg["data"]=bytes2str(Quote)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryCombInstrumentGuard(self,CombInstrumentGuard,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryCombInstrumentGuard"
            msg["data"]=bytes2str(CombInstrumentGuard)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryCombAction(self,CombAction,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryCombAction"
            msg["data"]=bytes2str(CombAction)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryTransferSerial(self,TransferSerial,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryTransferSerial"
            msg["data"]=bytes2str(TransferSerial)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryAccountregister(self,Accountregister,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryAccountregister"
            msg["data"]=bytes2str(Accountregister)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspError(self,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspError"
            msg["data"]=bytes2str(RspInfo)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnInstrumentStatus(self,InstrumentStatus):
        msg={}
        msg["cmd"]="OnRtnInstrumentStatus"
        msg["data"]=bytes2str(InstrumentStatus)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnBulletin(self,Bulletin):
        msg={}
        msg["cmd"]="OnRtnBulletin"
        msg["data"]=bytes2str(Bulletin)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnTradingNotice(self,TradingNoticeInfo):
        msg={}
        msg["cmd"]="OnRtnTradingNotice"
        msg["data"]=bytes2str(TradingNoticeInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnErrorConditionalOrder(self,ErrorConditionalOrder):
        msg={}
        msg["cmd"]="OnRtnErrorConditionalOrder"
        msg["data"]=bytes2str(ErrorConditionalOrder)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnExecOrder(self,ExecOrder):
        msg={}
        msg["cmd"]="OnRtnExecOrder"
        msg["data"]=bytes2str(ExecOrder)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnExecOrderInsert(self,InputExecOrder, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnExecOrderInsert"
        msg["data"]=bytes2str(InputExecOrder)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnExecOrderAction(self,ExecOrderAction, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnExecOrderAction"
        msg["data"]=bytes2str(ExecOrderAction)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnForQuoteInsert(self,InputForQuote, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnForQuoteInsert"
        msg["data"]=bytes2str(InputForQuote)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnQuote(self,Quote):
        msg={}
        msg["cmd"]="OnRtnQuote"
        msg["data"]=bytes2str(Quote)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnQuoteInsert(self,InputQuote, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnQuoteInsert"
        msg["data"]=bytes2str(InputQuote)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnQuoteAction(self,QuoteAction, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnQuoteAction"
        msg["data"]=bytes2str(QuoteAction)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnForQuoteRsp(self,ForQuoteRsp):
        msg={}
        msg["cmd"]="OnRtnForQuoteRsp"
        msg["data"]=bytes2str(ForQuoteRsp)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnCFMMCTradingAccountToken(self,CFMMCTradingAccountToken):
        msg={}
        msg["cmd"]="OnRtnCFMMCTradingAccountToken"
        msg["data"]=bytes2str(CFMMCTradingAccountToken)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnBatchOrderAction(self,BatchOrderAction, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnBatchOrderAction"
        msg["data"]=bytes2str(BatchOrderAction)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnCombAction(self,CombAction):
        msg={}
        msg["cmd"]="OnRtnCombAction"
        msg["data"]=bytes2str(CombAction)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnCombActionInsert(self,InputCombAction, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnCombActionInsert"
        msg["data"]=bytes2str(InputCombAction)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryContractBank(self,ContractBank,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryContractBank"
            msg["data"]=bytes2str(ContractBank)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryParkedOrder(self,ParkedOrder,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryParkedOrder"
            msg["data"]=bytes2str(ParkedOrder)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryParkedOrderAction(self,ParkedOrderAction,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryParkedOrderAction"
            msg["data"]=bytes2str(ParkedOrderAction)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryTradingNotice(self,TradingNotice,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryTradingNotice"
            msg["data"]=bytes2str(TradingNotice)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryBrokerTradingParams(self,BrokerTradingParams,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryBrokerTradingParams"
            msg["data"]=bytes2str(BrokerTradingParams)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQryBrokerTradingAlgos(self,BrokerTradingAlgos,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQryBrokerTradingAlgos"
            msg["data"]=bytes2str(BrokerTradingAlgos)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQueryCFMMCTradingAccountToken(self,QueryCFMMCTradingAccountToken,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQueryCFMMCTradingAccountToken"
            msg["data"]=bytes2str(QueryCFMMCTradingAccountToken)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnFromBankToFutureByBank(self,RspTransfer):
        msg={}
        msg["cmd"]="OnRtnFromBankToFutureByBank"
        msg["data"]=bytes2str(RspTransfer)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnFromFutureToBankByBank(self,RspTransfer):
        msg={}
        msg["cmd"]="OnRtnFromFutureToBankByBank"
        msg["data"]=bytes2str(RspTransfer)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnRepealFromBankToFutureByBank(self,RspRepeal):
        msg={}
        msg["cmd"]="OnRtnRepealFromBankToFutureByBank"
        msg["data"]=bytes2str(RspRepeal)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnRepealFromFutureToBankByBank(self,RspRepeal):
        msg={}
        msg["cmd"]="OnRtnRepealFromFutureToBankByBank"
        msg["data"]=bytes2str(RspRepeal)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnFromBankToFutureByFuture(self,RspTransfer):
        msg={}
        msg["cmd"]="OnRtnFromBankToFutureByFuture"
        msg["data"]=bytes2str(RspTransfer)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnFromFutureToBankByFuture(self,RspTransfer):
        msg={}
        msg["cmd"]="OnRtnFromFutureToBankByFuture"
        msg["data"]=bytes2str(RspTransfer)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnRepealFromBankToFutureByFutureManual(self,RspRepeal):
        msg={}
        msg["cmd"]="OnRtnRepealFromBankToFutureByFutureManual"
        msg["data"]=bytes2str(RspRepeal)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnRepealFromFutureToBankByFutureManual(self,RspRepeal):
        msg={}
        msg["cmd"]="OnRtnRepealFromFutureToBankByFutureManual"
        msg["data"]=bytes2str(RspRepeal)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnQueryBankBalanceByFuture(self,NotifyQueryAccount):
        msg={}
        msg["cmd"]="OnRtnQueryBankBalanceByFuture"
        msg["data"]=bytes2str(NotifyQueryAccount)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnBankToFutureByFuture(self,ReqTransfer, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnBankToFutureByFuture"
        msg["data"]=bytes2str(ReqTransfer)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnFutureToBankByFuture(self,ReqTransfer, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnFutureToBankByFuture"
        msg["data"]=bytes2str(ReqTransfer)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnRepealBankToFutureByFutureManual(self,ReqRepeal, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnRepealBankToFutureByFutureManual"
        msg["data"]=bytes2str(ReqRepeal)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnRepealFutureToBankByFutureManual(self,ReqRepeal, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnRepealFutureToBankByFutureManual"
        msg["data"]=bytes2str(ReqRepeal)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnErrRtnQueryBankBalanceByFuture(self,ReqQueryAccount, RspInfo):
        msg={}
        msg["cmd"]="OnErrRtnQueryBankBalanceByFuture"
        msg["data"]=bytes2str(ReqQueryAccount)
        msg["RspInfo"]=bytes2str(RspInfo)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnRepealFromBankToFutureByFuture(self,RspRepeal):
        msg={}
        msg["cmd"]="OnRtnRepealFromBankToFutureByFuture"
        msg["data"]=bytes2str(RspRepeal)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnRepealFromFutureToBankByFuture(self,RspRepeal):
        msg={}
        msg["cmd"]="OnRtnRepealFromFutureToBankByFuture"
        msg["data"]=bytes2str(RspRepeal)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspFromBankToFutureByFuture(self,ReqTransfer,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspFromBankToFutureByFuture"
            msg["data"]=bytes2str(ReqTransfer)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspFromFutureToBankByFuture(self,ReqTransfer,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspFromFutureToBankByFuture"
            msg["data"]=bytes2str(ReqTransfer)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRspQueryBankAccountMoneyByFuture(self,ReqQueryAccount,RspInfo, RequestID, IsLast):
        if RequestID in self.__idmap.keys():
            msg={}
            msg["cmd"]="OnRspQueryBankAccountMoneyByFuture"
            msg["data"]=bytes2str(ReqQueryAccount)
            msg["RspInfo"]=bytes2str(RspInfo)
            msg["RequestID"]=self.__idmap[RequestID]
            msg["IsLast"]=IsLast
            mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnOpenAccountByBank(self,OpenAccount):
        msg={}
        msg["cmd"]="OnRtnOpenAccountByBank"
        msg["data"]=bytes2str(OpenAccount)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnCancelAccountByBank(self,CancelAccount):
        msg={}
        msg["cmd"]="OnRtnCancelAccountByBank"
        msg["data"]=bytes2str(CancelAccount)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def OnRtnChangeAccountByBank(self,ChangeAccount):
        msg={}
        msg["cmd"]="OnRtnChangeAccountByBank"
        msg["data"]=bytes2str(ChangeAccount)
        mh.safesend(self.__subject_down,self.__InvestorIDstr,msg)
    def reqUserLogin(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcReqUserLoginField=dict( 
            TradingDay=b''
            ,BrokerID=self.__BrokerID
            ,UserID=self.__UserID
            ,Password=b''
            ,UserProductInfo=b''
            ,InterfaceProductInfo=b''
            ,ProtocolInfo=b''
            ,MacAddress=self.__MacAddress
            ,OneTimePassword=b''
            ,ClientIPAddress=b''
            ,LoginRemark=b''
            ,ClientIPPort=0
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcReqUserLoginField.keys():
                CThostFtdcReqUserLoginField[k]=v
        self.ReqUserLogin(CThostFtdcReqUserLoginField,RequestID)
    def reqUserLogout(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcUserLogoutField=dict( 
            BrokerID=self.__BrokerID
            ,UserID=self.__UserID
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcUserLogoutField.keys():
                CThostFtdcUserLogoutField[k]=v
        self.ReqUserLogout(CThostFtdcUserLogoutField,RequestID)
    def reqUserPasswordUpdate(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcUserPasswordUpdateField=dict( 
            BrokerID=self.__BrokerID
            ,UserID=self.__UserID
            ,OldPassword=b''
            ,NewPassword=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcUserPasswordUpdateField.keys():
                CThostFtdcUserPasswordUpdateField[k]=v
        self.ReqUserPasswordUpdate(CThostFtdcUserPasswordUpdateField,RequestID)
    def reqTradingAccountPasswordUpdate(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcTradingAccountPasswordUpdateField=dict( 
            BrokerID=self.__BrokerID
            ,AccountID=b''
            ,OldPassword=b''
            ,NewPassword=b''
            ,CurrencyID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcTradingAccountPasswordUpdateField.keys():
                CThostFtdcTradingAccountPasswordUpdateField[k]=v
        self.ReqTradingAccountPasswordUpdate(CThostFtdcTradingAccountPasswordUpdateField,RequestID)
    def reqQueryMaxOrderVolume(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQueryMaxOrderVolumeField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,Direction=b''
            ,OffsetFlag=b''
            ,HedgeFlag=self.__HedgeFlag
            ,MaxVolume=0
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQueryMaxOrderVolumeField.keys():
                CThostFtdcQueryMaxOrderVolumeField[k]=v
        self.ReqQueryMaxOrderVolume(CThostFtdcQueryMaxOrderVolumeField,RequestID)
    def reqSettlementInfoConfirm(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcSettlementInfoConfirmField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,ConfirmDate=b''
            ,ConfirmTime=b''
            ,SettlementID=0
            ,AccountID=b''
            ,CurrencyID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcSettlementInfoConfirmField.keys():
                CThostFtdcSettlementInfoConfirmField[k]=v
        self.ReqSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField,RequestID)
    def reqRemoveParkedOrder(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcRemoveParkedOrderField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,ParkedOrderID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcRemoveParkedOrderField.keys():
                CThostFtdcRemoveParkedOrderField[k]=v
        self.ReqRemoveParkedOrder(CThostFtdcRemoveParkedOrderField,RequestID)
    def reqRemoveParkedOrderAction(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcRemoveParkedOrderActionField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,ParkedOrderActionID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcRemoveParkedOrderActionField.keys():
                CThostFtdcRemoveParkedOrderActionField[k]=v
        self.ReqRemoveParkedOrderAction(CThostFtdcRemoveParkedOrderActionField,RequestID)
    def reqExecOrderInsert(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcInputExecOrderField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExecOrderRef=b''
            ,UserID=self.__UserID
            ,Volume=0
            ,RequestID=self.__RequestID
            ,BusinessUnit=b''
            ,OffsetFlag=b''
            ,HedgeFlag=self.__HedgeFlag
            ,ActionType=b''
            ,PosiDirection=b''
            ,ReservePositionFlag=b''
            ,CloseFlag=b''
            ,ExchangeID=b''
            ,InvestUnitID=b''
            ,AccountID=b''
            ,CurrencyID=b''
            ,ClientID=b''
            ,IPAddress=self.__IPAddress
            ,MacAddress=self.__MacAddress
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcInputExecOrderField.keys():
                CThostFtdcInputExecOrderField[k]=v
        self.ReqExecOrderInsert(CThostFtdcInputExecOrderField,RequestID)
    def reqExecOrderAction(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcInputExecOrderActionField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,ExecOrderActionRef=0
            ,ExecOrderRef=b''
            ,RequestID=self.__RequestID
            ,FrontID=0
            ,SessionID=0
            ,ExchangeID=b''
            ,ExecOrderSysID=b''
            ,ActionFlag=b''
            ,UserID=self.__UserID
            ,InstrumentID=b''
            ,InvestUnitID=b''
            ,IPAddress=self.__IPAddress
            ,MacAddress=self.__MacAddress
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcInputExecOrderActionField.keys():
                CThostFtdcInputExecOrderActionField[k]=v
        self.ReqExecOrderAction(CThostFtdcInputExecOrderActionField,RequestID)
    def reqForQuoteInsert(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcInputForQuoteField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ForQuoteRef=b''
            ,UserID=self.__UserID
            ,ExchangeID=b''
            ,InvestUnitID=b''
            ,IPAddress=self.__IPAddress
            ,MacAddress=self.__MacAddress
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcInputForQuoteField.keys():
                CThostFtdcInputForQuoteField[k]=v
        self.ReqForQuoteInsert(CThostFtdcInputForQuoteField,RequestID)
    def reqQuoteInsert(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcInputQuoteField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,QuoteRef=b''
            ,UserID=self.__UserID
            ,AskPrice=0.0
            ,BidPrice=0.0
            ,AskVolume=0
            ,BidVolume=0
            ,RequestID=self.__RequestID
            ,BusinessUnit=b''
            ,AskOffsetFlag=b''
            ,BidOffsetFlag=b''
            ,AskHedgeFlag=b''
            ,BidHedgeFlag=b''
            ,AskOrderRef=b''
            ,BidOrderRef=b''
            ,ForQuoteSysID=b''
            ,ExchangeID=b''
            ,InvestUnitID=b''
            ,ClientID=b''
            ,IPAddress=self.__IPAddress
            ,MacAddress=self.__MacAddress
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcInputQuoteField.keys():
                CThostFtdcInputQuoteField[k]=v
        self.ReqQuoteInsert(CThostFtdcInputQuoteField,RequestID)
    def reqQuoteAction(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcInputQuoteActionField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,QuoteActionRef=0
            ,QuoteRef=b''
            ,RequestID=self.__RequestID
            ,FrontID=0
            ,SessionID=0
            ,ExchangeID=b''
            ,QuoteSysID=b''
            ,ActionFlag=b''
            ,UserID=self.__UserID
            ,InstrumentID=b''
            ,InvestUnitID=b''
            ,ClientID=b''
            ,IPAddress=self.__IPAddress
            ,MacAddress=self.__MacAddress
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcInputQuoteActionField.keys():
                CThostFtdcInputQuoteActionField[k]=v
        self.ReqQuoteAction(CThostFtdcInputQuoteActionField,RequestID)
    def reqBatchOrderAction(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcInputBatchOrderActionField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,OrderActionRef=0
            ,RequestID=self.__RequestID
            ,FrontID=0
            ,SessionID=0
            ,ExchangeID=b''
            ,UserID=self.__UserID
            ,InvestUnitID=b''
            ,IPAddress=self.__IPAddress
            ,MacAddress=self.__MacAddress
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcInputBatchOrderActionField.keys():
                CThostFtdcInputBatchOrderActionField[k]=v
        self.ReqBatchOrderAction(CThostFtdcInputBatchOrderActionField,RequestID)
    def reqCombActionInsert(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcInputCombActionField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,CombActionRef=b''
            ,UserID=self.__UserID
            ,Direction=b''
            ,Volume=0
            ,CombDirection=b''
            ,HedgeFlag=self.__HedgeFlag
            ,ExchangeID=b''
            ,IPAddress=self.__IPAddress
            ,MacAddress=self.__MacAddress
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcInputCombActionField.keys():
                CThostFtdcInputCombActionField[k]=v
        self.ReqCombActionInsert(CThostFtdcInputCombActionField,RequestID)
    def reqQryOrder(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryOrderField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,OrderSysID=b''
            ,InsertTimeStart=b''
            ,InsertTimeEnd=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryOrderField.keys():
                CThostFtdcQryOrderField[k]=v
        self.ReqQryOrder(CThostFtdcQryOrderField,RequestID)
    def reqQryTrade(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryTradeField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,TradeID=b''
            ,TradeTimeStart=b''
            ,TradeTimeEnd=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryTradeField.keys():
                CThostFtdcQryTradeField[k]=v
        self.ReqQryTrade(CThostFtdcQryTradeField,RequestID)
    def reqQryInvestorPosition(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryInvestorPositionField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryInvestorPositionField.keys():
                CThostFtdcQryInvestorPositionField[k]=v
        self.ReqQryInvestorPosition(CThostFtdcQryInvestorPositionField,RequestID)
    def reqQryTradingAccount(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryTradingAccountField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,CurrencyID=b''
            ,BizType=b''
            ,AccountID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryTradingAccountField.keys():
                CThostFtdcQryTradingAccountField[k]=v
        self.ReqQryTradingAccount(CThostFtdcQryTradingAccountField,RequestID)
    def reqQryInvestor(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryInvestorField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryInvestorField.keys():
                CThostFtdcQryInvestorField[k]=v
        self.ReqQryInvestor(CThostFtdcQryInvestorField,RequestID)
    def reqQryTradingCode(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryTradingCodeField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,ExchangeID=b''
            ,ClientID=b''
            ,ClientIDType=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryTradingCodeField.keys():
                CThostFtdcQryTradingCodeField[k]=v
        self.ReqQryTradingCode(CThostFtdcQryTradingCodeField,RequestID)
    def reqQryInstrumentMarginRate(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryInstrumentMarginRateField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,HedgeFlag=self.__HedgeFlag
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryInstrumentMarginRateField.keys():
                CThostFtdcQryInstrumentMarginRateField[k]=v
        self.ReqQryInstrumentMarginRate(CThostFtdcQryInstrumentMarginRateField,RequestID)
    def reqQryInstrumentCommissionRate(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryInstrumentCommissionRateField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryInstrumentCommissionRateField.keys():
                CThostFtdcQryInstrumentCommissionRateField[k]=v
        self.ReqQryInstrumentCommissionRate(CThostFtdcQryInstrumentCommissionRateField,RequestID)
    def reqQryExchange(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryExchangeField=dict( 
            ExchangeID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryExchangeField.keys():
                CThostFtdcQryExchangeField[k]=v
        self.ReqQryExchange(CThostFtdcQryExchangeField,RequestID)
    def reqQryProduct(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryProductField=dict( 
            ProductID=b''
            ,ProductClass=b''
            ,ExchangeID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryProductField.keys():
                CThostFtdcQryProductField[k]=v
        self.ReqQryProduct(CThostFtdcQryProductField,RequestID)
    def reqQryInstrument(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryInstrumentField=dict( 
            InstrumentID=b''
            ,ExchangeID=b''
            ,ExchangeInstID=b''
            ,ProductID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryInstrumentField.keys():
                CThostFtdcQryInstrumentField[k]=v
        self.ReqQryInstrument(CThostFtdcQryInstrumentField,RequestID)
    def reqQryDepthMarketData(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryDepthMarketDataField=dict( 
            InstrumentID=b''
            ,ExchangeID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryDepthMarketDataField.keys():
                CThostFtdcQryDepthMarketDataField[k]=v
        self.ReqQryDepthMarketData(CThostFtdcQryDepthMarketDataField,RequestID)
    def reqQrySettlementInfo(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQrySettlementInfoField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,TradingDay=b''
            ,AccountID=b''
            ,CurrencyID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQrySettlementInfoField.keys():
                CThostFtdcQrySettlementInfoField[k]=v
        self.ReqQrySettlementInfo(CThostFtdcQrySettlementInfoField,RequestID)
    def reqQryTransferBank(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryTransferBankField=dict( 
            BankID=b''
            ,BankBrchID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryTransferBankField.keys():
                CThostFtdcQryTransferBankField[k]=v
        self.ReqQryTransferBank(CThostFtdcQryTransferBankField,RequestID)
    def reqQryInvestorPositionDetail(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryInvestorPositionDetailField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryInvestorPositionDetailField.keys():
                CThostFtdcQryInvestorPositionDetailField[k]=v
        self.ReqQryInvestorPositionDetail(CThostFtdcQryInvestorPositionDetailField,RequestID)
    def reqQryNotice(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryNoticeField=dict( 
            BrokerID=self.__BrokerID
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryNoticeField.keys():
                CThostFtdcQryNoticeField[k]=v
        self.ReqQryNotice(CThostFtdcQryNoticeField,RequestID)
    def reqQrySettlementInfoConfirm(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQrySettlementInfoConfirmField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,AccountID=b''
            ,CurrencyID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQrySettlementInfoConfirmField.keys():
                CThostFtdcQrySettlementInfoConfirmField[k]=v
        self.ReqQrySettlementInfoConfirm(CThostFtdcQrySettlementInfoConfirmField,RequestID)
    def reqQryInvestorPositionCombineDetail(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryInvestorPositionCombineDetailField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,CombInstrumentID=b''
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryInvestorPositionCombineDetailField.keys():
                CThostFtdcQryInvestorPositionCombineDetailField[k]=v
        self.ReqQryInvestorPositionCombineDetail(CThostFtdcQryInvestorPositionCombineDetailField,RequestID)
    def reqQryCFMMCTradingAccountKey(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryCFMMCTradingAccountKeyField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryCFMMCTradingAccountKeyField.keys():
                CThostFtdcQryCFMMCTradingAccountKeyField[k]=v
        self.ReqQryCFMMCTradingAccountKey(CThostFtdcQryCFMMCTradingAccountKeyField,RequestID)
    def reqQryEWarrantOffset(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryEWarrantOffsetField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,ExchangeID=b''
            ,InstrumentID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryEWarrantOffsetField.keys():
                CThostFtdcQryEWarrantOffsetField[k]=v
        self.ReqQryEWarrantOffset(CThostFtdcQryEWarrantOffsetField,RequestID)
    def reqQryInvestorProductGroupMargin(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryInvestorProductGroupMarginField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,ProductGroupID=b''
            ,HedgeFlag=self.__HedgeFlag
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryInvestorProductGroupMarginField.keys():
                CThostFtdcQryInvestorProductGroupMarginField[k]=v
        self.ReqQryInvestorProductGroupMargin(CThostFtdcQryInvestorProductGroupMarginField,RequestID)
    def reqQryExchangeMarginRate(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryExchangeMarginRateField=dict( 
            BrokerID=self.__BrokerID
            ,InstrumentID=b''
            ,HedgeFlag=self.__HedgeFlag
            ,ExchangeID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryExchangeMarginRateField.keys():
                CThostFtdcQryExchangeMarginRateField[k]=v
        self.ReqQryExchangeMarginRate(CThostFtdcQryExchangeMarginRateField,RequestID)
    def reqQryExchangeMarginRateAdjust(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryExchangeMarginRateAdjustField=dict( 
            BrokerID=self.__BrokerID
            ,InstrumentID=b''
            ,HedgeFlag=self.__HedgeFlag
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryExchangeMarginRateAdjustField.keys():
                CThostFtdcQryExchangeMarginRateAdjustField[k]=v
        self.ReqQryExchangeMarginRateAdjust(CThostFtdcQryExchangeMarginRateAdjustField,RequestID)
    def reqQryExchangeRate(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryExchangeRateField=dict( 
            BrokerID=self.__BrokerID
            ,FromCurrencyID=b''
            ,ToCurrencyID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryExchangeRateField.keys():
                CThostFtdcQryExchangeRateField[k]=v
        self.ReqQryExchangeRate(CThostFtdcQryExchangeRateField,RequestID)
    def reqQrySecAgentACIDMap(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQrySecAgentACIDMapField=dict( 
            BrokerID=self.__BrokerID
            ,UserID=self.__UserID
            ,AccountID=b''
            ,CurrencyID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQrySecAgentACIDMapField.keys():
                CThostFtdcQrySecAgentACIDMapField[k]=v
        self.ReqQrySecAgentACIDMap(CThostFtdcQrySecAgentACIDMapField,RequestID)
    def reqQryProductExchRate(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryProductExchRateField=dict( 
            ProductID=b''
            ,ExchangeID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryProductExchRateField.keys():
                CThostFtdcQryProductExchRateField[k]=v
        self.ReqQryProductExchRate(CThostFtdcQryProductExchRateField,RequestID)
    def reqQryProductGroup(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryProductGroupField=dict( 
            ProductID=b''
            ,ExchangeID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryProductGroupField.keys():
                CThostFtdcQryProductGroupField[k]=v
        self.ReqQryProductGroup(CThostFtdcQryProductGroupField,RequestID)
    def reqQryMMInstrumentCommissionRate(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryMMInstrumentCommissionRateField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryMMInstrumentCommissionRateField.keys():
                CThostFtdcQryMMInstrumentCommissionRateField[k]=v
        self.ReqQryMMInstrumentCommissionRate(CThostFtdcQryMMInstrumentCommissionRateField,RequestID)
    def reqQryMMOptionInstrCommRate(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryMMOptionInstrCommRateField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryMMOptionInstrCommRateField.keys():
                CThostFtdcQryMMOptionInstrCommRateField[k]=v
        self.ReqQryMMOptionInstrCommRate(CThostFtdcQryMMOptionInstrCommRateField,RequestID)
    def reqQryInstrumentOrderCommRate(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryInstrumentOrderCommRateField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryInstrumentOrderCommRateField.keys():
                CThostFtdcQryInstrumentOrderCommRateField[k]=v
        self.ReqQryInstrumentOrderCommRate(CThostFtdcQryInstrumentOrderCommRateField,RequestID)
    def reqQryOptionInstrTradeCost(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryOptionInstrTradeCostField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,HedgeFlag=self.__HedgeFlag
            ,InputPrice=0.0
            ,UnderlyingPrice=0.0
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryOptionInstrTradeCostField.keys():
                CThostFtdcQryOptionInstrTradeCostField[k]=v
        self.ReqQryOptionInstrTradeCost(CThostFtdcQryOptionInstrTradeCostField,RequestID)
    def reqQryOptionInstrCommRate(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryOptionInstrCommRateField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryOptionInstrCommRateField.keys():
                CThostFtdcQryOptionInstrCommRateField[k]=v
        self.ReqQryOptionInstrCommRate(CThostFtdcQryOptionInstrCommRateField,RequestID)
    def reqQryExecOrder(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryExecOrderField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,ExecOrderSysID=b''
            ,InsertTimeStart=b''
            ,InsertTimeEnd=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryExecOrderField.keys():
                CThostFtdcQryExecOrderField[k]=v
        self.ReqQryExecOrder(CThostFtdcQryExecOrderField,RequestID)
    def reqQryForQuote(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryForQuoteField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,InsertTimeStart=b''
            ,InsertTimeEnd=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryForQuoteField.keys():
                CThostFtdcQryForQuoteField[k]=v
        self.ReqQryForQuote(CThostFtdcQryForQuoteField,RequestID)
    def reqQryQuote(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryQuoteField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,QuoteSysID=b''
            ,InsertTimeStart=b''
            ,InsertTimeEnd=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryQuoteField.keys():
                CThostFtdcQryQuoteField[k]=v
        self.ReqQryQuote(CThostFtdcQryQuoteField,RequestID)
    def reqQryCombInstrumentGuard(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryCombInstrumentGuardField=dict( 
            BrokerID=self.__BrokerID
            ,InstrumentID=b''
            ,ExchangeID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryCombInstrumentGuardField.keys():
                CThostFtdcQryCombInstrumentGuardField[k]=v
        self.ReqQryCombInstrumentGuard(CThostFtdcQryCombInstrumentGuardField,RequestID)
    def reqQryCombAction(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryCombActionField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryCombActionField.keys():
                CThostFtdcQryCombActionField[k]=v
        self.ReqQryCombAction(CThostFtdcQryCombActionField,RequestID)
    def reqQryTransferSerial(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryTransferSerialField=dict( 
            BrokerID=self.__BrokerID
            ,AccountID=b''
            ,BankID=b''
            ,CurrencyID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryTransferSerialField.keys():
                CThostFtdcQryTransferSerialField[k]=v
        self.ReqQryTransferSerial(CThostFtdcQryTransferSerialField,RequestID)
    def reqQryAccountregister(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryAccountregisterField=dict( 
            BrokerID=self.__BrokerID
            ,AccountID=b''
            ,BankID=b''
            ,BankBranchID=b''
            ,CurrencyID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryAccountregisterField.keys():
                CThostFtdcQryAccountregisterField[k]=v
        self.ReqQryAccountregister(CThostFtdcQryAccountregisterField,RequestID)
    def reqQryContractBank(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryContractBankField=dict( 
            BrokerID=self.__BrokerID
            ,BankID=b''
            ,BankBrchID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryContractBankField.keys():
                CThostFtdcQryContractBankField[k]=v
        self.ReqQryContractBank(CThostFtdcQryContractBankField,RequestID)
    def reqQryParkedOrder(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryParkedOrderField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryParkedOrderField.keys():
                CThostFtdcQryParkedOrderField[k]=v
        self.ReqQryParkedOrder(CThostFtdcQryParkedOrderField,RequestID)
    def reqQryParkedOrderAction(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryParkedOrderActionField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InstrumentID=b''
            ,ExchangeID=b''
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryParkedOrderActionField.keys():
                CThostFtdcQryParkedOrderActionField[k]=v
        self.ReqQryParkedOrderAction(CThostFtdcQryParkedOrderActionField,RequestID)
    def reqQryTradingNotice(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryTradingNoticeField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryTradingNoticeField.keys():
                CThostFtdcQryTradingNoticeField[k]=v
        self.ReqQryTradingNotice(CThostFtdcQryTradingNoticeField,RequestID)
    def reqQryBrokerTradingParams(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryBrokerTradingParamsField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,CurrencyID=b''
            ,AccountID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryBrokerTradingParamsField.keys():
                CThostFtdcQryBrokerTradingParamsField[k]=v
        self.ReqQryBrokerTradingParams(CThostFtdcQryBrokerTradingParamsField,RequestID)
    def reqQryBrokerTradingAlgos(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQryBrokerTradingAlgosField=dict( 
            BrokerID=self.__BrokerID
            ,ExchangeID=b''
            ,InstrumentID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQryBrokerTradingAlgosField.keys():
                CThostFtdcQryBrokerTradingAlgosField[k]=v
        self.ReqQryBrokerTradingAlgos(CThostFtdcQryBrokerTradingAlgosField,RequestID)
    def reqQueryCFMMCTradingAccountToken(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcQueryCFMMCTradingAccountTokenField=dict( 
            BrokerID=self.__BrokerID
            ,InvestorID=self.__InvestorID
            ,InvestUnitID=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcQueryCFMMCTradingAccountTokenField.keys():
                CThostFtdcQueryCFMMCTradingAccountTokenField[k]=v
        self.ReqQueryCFMMCTradingAccountToken(CThostFtdcQueryCFMMCTradingAccountTokenField,RequestID)
    def reqFromBankToFutureByFuture(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcReqTransferField=dict( 
            TradeCode=b''
            ,BankID=b''
            ,BankBranchID=b''
            ,BrokerID=self.__BrokerID
            ,BrokerBranchID=b''
            ,TradeDate=b''
            ,TradeTime=b''
            ,BankSerial=b''
            ,TradingDay=b''
            ,PlateSerial=0
            ,LastFragment=b''
            ,SessionID=0
            ,CustomerName=b''
            ,IdCardType=b''
            ,IdentifiedCardNo=b''
            ,CustType=b''
            ,BankAccount=b''
            ,BankPassWord=b''
            ,AccountID=b''
            ,Password=b''
            ,InstallID=0
            ,FutureSerial=0
            ,UserID=self.__UserID
            ,VerifyCertNoFlag=b''
            ,CurrencyID=b''
            ,TradeAmount=0.0
            ,FutureFetchAmount=0.0
            ,FeePayFlag=b''
            ,CustFee=0.0
            ,BrokerFee=0.0
            ,Message=b''
            ,Digest=b''
            ,BankAccType=b''
            ,DeviceID=b''
            ,BankSecuAccType=b''
            ,BrokerIDByBank=b''
            ,BankSecuAcc=b''
            ,BankPwdFlag=b''
            ,SecuPwdFlag=b''
            ,OperNo=b''
            ,RequestID=self.__RequestID
            ,TID=0
            ,TransferStatus=b''
            ,LongCustomerName=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcReqTransferField.keys():
                CThostFtdcReqTransferField[k]=v
        self.ReqFromBankToFutureByFuture(CThostFtdcReqTransferField,RequestID)
    def reqFromFutureToBankByFuture(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcReqTransferField=dict( 
            TradeCode=b''
            ,BankID=b''
            ,BankBranchID=b''
            ,BrokerID=self.__BrokerID
            ,BrokerBranchID=b''
            ,TradeDate=b''
            ,TradeTime=b''
            ,BankSerial=b''
            ,TradingDay=b''
            ,PlateSerial=0
            ,LastFragment=b''
            ,SessionID=0
            ,CustomerName=b''
            ,IdCardType=b''
            ,IdentifiedCardNo=b''
            ,CustType=b''
            ,BankAccount=b''
            ,BankPassWord=b''
            ,AccountID=b''
            ,Password=b''
            ,InstallID=0
            ,FutureSerial=0
            ,UserID=self.__UserID
            ,VerifyCertNoFlag=b''
            ,CurrencyID=b''
            ,TradeAmount=0.0
            ,FutureFetchAmount=0.0
            ,FeePayFlag=b''
            ,CustFee=0.0
            ,BrokerFee=0.0
            ,Message=b''
            ,Digest=b''
            ,BankAccType=b''
            ,DeviceID=b''
            ,BankSecuAccType=b''
            ,BrokerIDByBank=b''
            ,BankSecuAcc=b''
            ,BankPwdFlag=b''
            ,SecuPwdFlag=b''
            ,OperNo=b''
            ,RequestID=self.__RequestID
            ,TID=0
            ,TransferStatus=b''
            ,LongCustomerName=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcReqTransferField.keys():
                CThostFtdcReqTransferField[k]=v
        self.ReqFromFutureToBankByFuture(CThostFtdcReqTransferField,RequestID)
    def reqQueryBankAccountMoneyByFuture(self,rsq): 
        RequestID=self.__IncRequestID()
        self.__idmap[RequestID]=rsq["RequestID"]
        rsq=str2bytes(rsq)
        CThostFtdcReqQueryAccountField=dict( 
            TradeCode=b''
            ,BankID=b''
            ,BankBranchID=b''
            ,BrokerID=self.__BrokerID
            ,BrokerBranchID=b''
            ,TradeDate=b''
            ,TradeTime=b''
            ,BankSerial=b''
            ,TradingDay=b''
            ,PlateSerial=0
            ,LastFragment=b''
            ,SessionID=0
            ,CustomerName=b''
            ,IdCardType=b''
            ,IdentifiedCardNo=b''
            ,CustType=b''
            ,BankAccount=b''
            ,BankPassWord=b''
            ,AccountID=b''
            ,Password=b''
            ,FutureSerial=0
            ,InstallID=0
            ,UserID=self.__UserID
            ,VerifyCertNoFlag=b''
            ,CurrencyID=b''
            ,Digest=b''
            ,BankAccType=b''
            ,DeviceID=b''
            ,BankSecuAccType=b''
            ,BrokerIDByBank=b''
            ,BankSecuAcc=b''
            ,BankPwdFlag=b''
            ,SecuPwdFlag=b''
            ,OperNo=b''
            ,RequestID=self.__RequestID
            ,TID=0
            ,LongCustomerName=b''
        ) 
        for (k,v) in rsq.items(): 
            if k in CThostFtdcReqQueryAccountField.keys():
                CThostFtdcReqQueryAccountField[k]=v
        self.ReqQueryBankAccountMoneyByFuture(CThostFtdcReqQueryAccountField,RequestID)
